package com.balance.exception;

import com.balance.pojo.common.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.HandlerMethod;

import java.lang.constant.Constable;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @Title: ExceptionController
 * @Author 小东
 * @Package com.balance.exception
 * @Date 2025/3/28 14:33
 * @description: 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionController {


    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public CommonResult sameArgException(SQLIntegrityConstraintViolationException se){
        return CommonResult.error(se.getMessage()+"注解：当前添加的用户已经存在该权限");
    }

    @ExceptionHandler(Exception.class)
    public CommonResult ServerException(Exception e, HandlerMethod hm){
        System.out.println(e.getMessage());
        System.out.println(hm.getBean().getClass()+"出现问题");
        System.out.println(hm.getMethod().getName()+"出现问题");
        return CommonResult.error("服务器内部出现错误");
    }
}
